 use "$data\women_analysis.dta", clear
  
 global controlwoman mbase_ageyears  fdstotal rantime ranerror numberkids
 global controlhh land members adults mbase_electrified  mbase_OB mbase_scheduled

 replace heard_learner=0 if heard_learner==2
 replace heard_hus=0 if heard_hus==2
 gen difference=abs(tab_learner- tab_hus)
 gen gamma=(tab_joint-tab_hus)/(tab_learner-tab_hus)
 gen Dgamma=0 if gamma<0.5 & gamma>=0
 replace Dgamma=1 if gamma>0.5 & gamma<=1 
 replace gamma=99 if tab_learner==tab_hus & tab_learner~=.
 tab gamma if sequence==1
 replace gamma=. if gamma<0
 replace gamma=. if gamma>1
 rename withinHHID learner_pid 
 gen womanspeakfirst=1 if learner_pid==firstspeaker_pid
 replace womanspeakfirst=0 if learner_pid~=firstspeaker_pid & firstspeaker_pid~=""
 gen womanspeaklast=1 if learner_pid==lastspeaker_pid
 replace womanspeaklast=0 if learner_pid~=lastspeaker_pid & lastspeaker_pid~=""
 tab difference if sequence==1

 estimates clear
 foreach i in tab_learner tab_hus difference{
 ivregress 2sls `i' (participatedTA_IV=ITTanalysis) i.strata $controlwoman $controlhh if sequence==1, vce(robust)
 est store `i'
 su `i' if sequence==1 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 }
 
 ivregress 2sls gamma (participatedTA_IV=ITTanalysis) i.strata $controlwoman $controlhh if sequence==1 & gamma>=0 & gamma<=1, vce(robust)
 est store gamma
 su gamma if sequence==1 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 
 foreach i in Dgamma womanspeakfirst womanspeaklast suggest_decider seek_valution dictate_valuation heard_learner heard_hus{
 ivregress 2sls `i' (participatedTA_IV=ITTanalysis) i.strata $controlwoman $controlhh if sequence==1, vce(robust)
 est store `i'
 su `i' if sequence==1 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 }
 
 esttab * using "$results\Table7.xls", stat(controlmean N r2) keep (participatedTA_IV) b(3) se(3) replace
 
 ***FDR q-values
 *The FDR Q-values are computed following  Benjamini and Hochberg (1995) within each category.
 
 exit
 
 
 
 
 
 